/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Main;

import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JOptionPane;
import javax.swing.JProgressBar;
import javax.swing.JRadioButton;
import javax.swing.JTextPane;
import javax.swing.text.BadLocationException;
import ordenacao.*;

/**
 *
 * @author ufabc
 */
public class Interface extends javax.swing.JFrame {

    Vetor exe;
    int ParamtroN, ParametroT = 1;

    /**
     * Creates new form Interface
     */
    public Interface() {
        initComponents();
        exe = new Vetor();
        this.txtParametroT.setText("1");



        this.chkQuisckSort.setSelected(true);
        this.chkMergesort.setSelected(true);
        this.chkbubbleSort.setSelected(true);
        this.chkselectionSort.setSelected(true);
        this.chkinsertionSort.setSelected(true);
        this.chkHeapSort.setSelected(true);

    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        buttonGroup2 = new javax.swing.ButtonGroup();
        txtParametroN = new javax.swing.JTextField();
        btnIniciarTestes = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        chkHeapSort = new javax.swing.JCheckBox();
        chkQuisckSort = new javax.swing.JCheckBox();
        chkMergesort = new javax.swing.JCheckBox();
        chkbubbleSort = new javax.swing.JCheckBox();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        chkCrescente = new javax.swing.JRadioButton();
        chkAleatorios = new javax.swing.JRadioButton();
        chkDecrescente = new javax.swing.JRadioButton();
        lblParamtroT = new javax.swing.JLabel();
        txtParametroT = new javax.swing.JTextField();
        jSeparator1 = new javax.swing.JSeparator();
        jScrollPane1 = new javax.swing.JScrollPane();
        txtSaida = new javax.swing.JTextPane();
        chkselectionSort = new javax.swing.JCheckBox();
        chkinsertionSort = new javax.swing.JCheckBox();
        pgbProgresso = new javax.swing.JProgressBar();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("::Simulador de algoritmos::");
        setResizable(false);

        btnIniciarTestes.setText("Iniciar testes");
        btnIniciarTestes.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnIniciarTestesActionPerformed(evt);
            }
        });

        jLabel1.setText("Parâmetros:");

        chkHeapSort.setText("HeapSort");

        chkQuisckSort.setText("QuickSort");

        chkMergesort.setText("MergeSort");

        chkbubbleSort.setText("BubbleSort");

        jLabel2.setText("Utilizar os algoritmos:");

        jLabel3.setText("Tamanho do vetor(n):");

        buttonGroup2.add(chkCrescente);
        chkCrescente.setText("Dados de entrada ordenados (crescente)");

        buttonGroup2.add(chkAleatorios);
        chkAleatorios.setSelected(true);
        chkAleatorios.setText("Dados de entrada aleatórios");
        chkAleatorios.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                chkAleatoriosStateChanged(evt);
            }
        });
        chkAleatorios.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                chkAleatoriosActionPerformed(evt);
            }
        });

        buttonGroup2.add(chkDecrescente);
        chkDecrescente.setText("Dados de entrada ordenados (decrescente)");

        lblParamtroT.setText("Quantidade de testes(t):");

        txtSaida.setEditable(false);
        txtSaida.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        jScrollPane1.setViewportView(txtSaida);

        chkselectionSort.setText("SelectionSort");

        chkinsertionSort.setText("InsertionSort");

        jLabel4.setText("Saida:");

        jLabel5.setText("Progresso:");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel1)
                            .addComponent(txtParametroN, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel3)
                            .addComponent(chkDecrescente)
                            .addComponent(chkAleatorios)
                            .addComponent(chkCrescente)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(10, 10, 10)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(lblParamtroT)
                                    .addComponent(txtParametroT, javax.swing.GroupLayout.PREFERRED_SIZE, 62, javax.swing.GroupLayout.PREFERRED_SIZE))))
                        .addGap(0, 0, Short.MAX_VALUE)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(chkMergesort)
                            .addComponent(chkHeapSort)
                            .addComponent(jLabel2)
                            .addComponent(chkQuisckSort)
                            .addComponent(chkbubbleSort)
                            .addComponent(btnIniciarTestes)
                            .addComponent(chkselectionSort)
                            .addComponent(chkinsertionSort))
                        .addGap(115, 115, 115))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel4)
                            .addComponent(jLabel5))
                        .addGap(0, 0, Short.MAX_VALUE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(pgbProgresso, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jScrollPane1))
                        .addContainerGap())))
            .addGroup(layout.createSequentialGroup()
                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 675, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 0, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(14, 14, 14)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(jLabel1))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(6, 6, 6)
                        .addComponent(chkHeapSort)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(chkMergesort)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(chkQuisckSort)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(chkbubbleSort)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(chkselectionSort)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(chkinsertionSort))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel3)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(txtParametroN, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(chkAleatorios)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(chkCrescente)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(chkDecrescente)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(lblParamtroT)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(txtParametroT, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(18, 18, 18)
                .addComponent(btnIniciarTestes)
                .addGap(18, 18, 18)
                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jLabel5)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(pgbProgresso, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabel4)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 223, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void chkAleatoriosActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_chkAleatoriosActionPerformed
    }//GEN-LAST:event_chkAleatoriosActionPerformed

    private void chkAleatoriosStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_chkAleatoriosStateChanged
        if (this.chkAleatorios.isSelected()) {
            this.txtParametroT.setEnabled(true);

        } else {
            this.txtParametroT.setText("1");
            this.txtParametroT.setEnabled(false);
            this.ParametroT = 0;

        }
    }//GEN-LAST:event_chkAleatoriosStateChanged

    private void btnIniciarTestesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnIniciarTestesActionPerformed

        if (ValidaForm()) {

            try {
                this.txtSaida.getStyledDocument().remove(0, this.txtSaida.getStyledDocument().getLength());
            } catch (BadLocationException ex) {
                Logger.getLogger(Interface.class.getName()).log(Level.SEVERE, null, ex);
            }

            this.btnIniciarTestes.setEnabled(false);
            new Thread(new SortEngine(this.ParamtroN, this.ParametroT, this)).start();


        }

    }//GEN-LAST:event_btnIniciarTestesActionPerformed

    private boolean ValidaForm() {
        boolean result = true;
        try {
            this.ParamtroN = Integer.parseInt(this.txtParametroN.getText());
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(null, "Valor inválido para tamanho de entrada (n)");
            result = false;
        }


        try {
            this.ParametroT = Integer.parseInt(this.txtParametroT.getText());
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(null, "Valor inválido para tamanho de entrada (t)");
            result = false;
        }

        return result;
    }

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(Interface.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Interface.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Interface.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Interface.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Interface().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnIniciarTestes;
    private javax.swing.ButtonGroup buttonGroup2;
    private javax.swing.JRadioButton chkAleatorios;
    private javax.swing.JRadioButton chkCrescente;
    private javax.swing.JRadioButton chkDecrescente;
    private javax.swing.JCheckBox chkHeapSort;
    private javax.swing.JCheckBox chkMergesort;
    private javax.swing.JCheckBox chkQuisckSort;
    private javax.swing.JCheckBox chkbubbleSort;
    private javax.swing.JCheckBox chkinsertionSort;
    private javax.swing.JCheckBox chkselectionSort;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JLabel lblParamtroT;
    private javax.swing.JProgressBar pgbProgresso;
    private javax.swing.JTextField txtParametroN;
    private javax.swing.JTextField txtParametroT;
    private javax.swing.JTextPane txtSaida;
    // End of variables declaration//GEN-END:variables

    public JProgressBar getPgbProgresso() {
        return pgbProgresso;
    }

    public JButton getBtnIniciarTestes() {
        return btnIniciarTestes;
    }

    public JCheckBox getChkHeapSort() {
        return chkHeapSort;
    }

    public JCheckBox getChkMergesort() {
        return chkMergesort;
    }

    public JCheckBox getChkQuisckSort() {
        return chkQuisckSort;
    }

    public JCheckBox getChkbubbleSort() {
        return chkbubbleSort;
    }

    public JCheckBox getChkinsertionSort() {
        return chkinsertionSort;
    }

    public JCheckBox getChkselectionSort() {
        return chkselectionSort;
    }

    public JTextPane getTxtSaida() {
        return txtSaida;
    }

    public JRadioButton getChkAleatorios() {
        return chkAleatorios;
    }

    public JRadioButton getChkCrescente() {
        return chkCrescente;
    }

    public JRadioButton getChkDecrescente() {
        return chkDecrescente;
    }
}
